(function(){
//Variables and functions go here.
//A good method to avoid global variables is creating a anonymous function that keeps our variable inside the function scope


//alert("WOW");

var ODP_Viewer = {

	//alert("I am inside fun");
	
	start_string : "Hello, Narendra",
	content_xml : "", 
	
	init : function (id, path){
		//alert(this.start_string);
		this.Container = $(id) ;
		this.Container.html("<p>Web based Open Office Presentation Viewer -v0.0000 - A effort to make a pure Javascript ODP Viewer</p><p>Current version show only text and images without formatting. For exmaple, You can see following slides,(Use Firefox 3.5+). Original version of following slides can be found at <a href='http://www.slideshare.net/narendra.sisodiya/introduction-to-foss-world'>http://www.slideshare.net/narendra.sisodiya/introduction-to-foss-world</a></p><div>(c) Narendra Sisodiya , released under GPLv3, Twitter <a href='http://twitter.com/eduvid'>http://twitter.com/eduvid</a> <p>Please join this project if you like it</p></div>")
		this.odp_path = path ;
		this.get_file();
		
	},
	
	content_load : function(){
		//alert("Data Loaded: " + this.content_xml);
		var self = this ; 
		this.slides = $(this.content_xml).find("[nodeName=draw:page]") ;
		this.slides_num = this.slides.length;
		this.ImageArray = new Array(self.slides_num);
		for(var i=0; i<self.slides_num; i++){

			this.ImageArray[i] = $(self.slides[i]).find("[nodeName=draw:image]") ;
			
		
		}//for
		
		
		
		this.thumbnail_src = this.odp_path + "/Thumbnails/thumbnail.png";
		
		//this.add_thumbnail();
		this.add_text_slides();

	},
	
	get_file : function (){
		var self = this ;

		jQuery.ajax({
			url:    self.odp_path + "/content.xml",
			
			success: function(data) {
				//alert(" Data Loaded" + data);
				self.content_xml = data;
				self.content_load();
			},
			
			async:   true/*,
			cache:   false,
			dataType: "xml"*/
		});
		
	
	},
	
	add_thumbnail : function(){
		var self = this ;
		this.Container.append("<img src='" + this.thumbnail_src +"'>");
	},
	
	add_text_slides : function (){
		var self = this;
		for(var i=0; i<this.slides_num; i++){
			var ImgSrc = "";
			for(var j=0; j< self.ImageArray[i].length ; j++){
				//console.log(i + "   --- " + j + "-->" + self.ImageArray[i][j].href);
				ImgSrc = ImgSrc + "<img src='" + self.odp_path + "/" + self.ImageArray[i][j].getAttribute("xlink:href") +"' />";
			}//for
			
			this.Container.append("<div class='slide'> <p>This is slide number " + i + "</p> <hr/> <p>"+self.slides[i].textContent+"</p> " + ImgSrc +" </div>");

			
				
		}//for
	
	}
	
	

};//ODP_Viewer

if(!window.$$$){
 	window.$$$ =  ODP_Viewer ;
 }else{
 	window.ODP_Viewer =  ODP_Viewer ;
}//if
})();

